package com.ticket.sass.admin.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ticket.sass.admin.annotation.AuthIgnore;
import com.ticket.sass.admin.business.AdminBusiness;
import com.ticket.sass.admin.business.ResourceBusiness;
import com.ticket.sass.admin.business.impl.TenantBusinessImpl;
import com.ticket.sass.admin.dto.PermResourceOutput;
import com.ticket.sass.admin.dto.input.admin.AdminLoginInput;
import com.ticket.sass.admin.dto.output.TenantInfoOutput;
import com.ticket.sass.admin.dto.output.admin.AdminInfoOutput;
import com.ticket.sass.admin.model.ResultModel;
import com.ticket.sass.admin.model.TokenModel;
import com.ticket.sass.admin.util.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author ywb
 * @date 2022-09-26 17:32
 */
@RestController
@AllArgsConstructor
@ApiSupport(order = 1)
@Api(tags = {"首页-模块"})
public class IndexController {
    
    final JwtUtil jwtUtil;
    final AdminBusiness adminBusiness;
    final ResourceBusiness resourceBusiness;
    final TenantBusinessImpl tenantBusiness;

    @AuthIgnore
    @PostMapping("/login")
    @ApiOperation(value = "管理员登录")
    public ResultModel<TokenModel> login(
        @RequestBody @Valid AdminLoginInput input
    ){
        return ResultModel.success(
            adminBusiness.login(input)
        );
    }
    
    @GetMapping("/info")
    @ApiOperation(value = "管理员基本信息")
    public ResultModel<AdminInfoOutput> info(){
        return ResultModel.success(
            adminBusiness.info()
        );
    }
    
    @AuthIgnore
    @GetMapping("/basic")
    @ApiOperation(value = "基本信息")
    public ResultModel<TenantInfoOutput> cinemaList(){
        return ResultModel.success(
            tenantBusiness.cinemaList()
        );
    }
    
    @ApiOperation(value = "资源")
    @GetMapping("/resource")
    public ResultModel<List<PermResourceOutput>> resource() {
        return ResultModel.success(
            resourceBusiness.permRecursionList()
        );
    }
}
